package com.hb.game.pk.ui.activity.game.erba;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.hb.game.pk.R;
import com.hb.game.pk.adpter.ErBaRecordListAdapter;
import com.hb.game.pk.adpter.ErBaTypeRecordListAdapter;
import com.hb.game.pk.api.Host;
import com.hb.game.pk.api.RedBag;
import com.hb.game.pk.base.BaseActivity;
import com.hb.game.pk.beans.ErBaXiaZhuInfo;
import com.hb.game.pk.beans.ErBaZhuangJiaInfo;
import com.hb.game.pk.beans.NullBean;
import com.hb.game.pk.network.RetrofitCreateHelper;
import com.hb.game.pk.utils.ToastUtils;
import com.hb.game.pk.widgets.titlebar.TitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ErBaRecordActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    private int type;
    private List<String> data;
    private List<ErBaXiaZhuInfo.DataBean> xzInfo;
    private List<ErBaZhuangJiaInfo.DataBean> zjInfo;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_game_room;
    }

    @Override
    protected int getRootViewId() {
        return R.id.layout_root;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return R.id.rv_list;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        Intent intent = getIntent();
        type = intent.getIntExtra("type", 0);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        titleBar.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ErBaRecordActivity.this.finish();
            }
        });
        String title = "";
        if (type == 1) {
            title = "下注记录";
        } else {
            title = "庄家记录";
        }
        titleBar.setTitle(title);
    }

    @Override
    protected void onRefreshData() {
        super.onRefreshData();
        if (type == 1) {
            // 下注记录
            Call<ErBaXiaZhuInfo> call = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).erba_xiazhuinfo();
            call.enqueue(new Callback<ErBaXiaZhuInfo>() {
                @Override
                public void onResponse(Call<ErBaXiaZhuInfo> call, Response<ErBaXiaZhuInfo> response) {
                    ErBaXiaZhuInfo body = response.body();
                    if (body == null) {
                        ToastUtils.showToast("请求错误");
                        return;
                    }
                    if (body.getStatus() != 1) {
                        ToastUtils.showToast(body.getInfo());
                        return;
                    }
                    xzInfo = body.getData();
                    initAdapter();
                }

                @Override
                public void onFailure(Call<ErBaXiaZhuInfo> call, Throwable t) {
                    ToastUtils.showToast("网络请求错误");
                }
            });
        } else {
            // 庄家记录
            Call<ErBaZhuangJiaInfo> call = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).erba_zhuanginfo();
            call.enqueue(new Callback<ErBaZhuangJiaInfo>() {
                @Override
                public void onResponse(Call<ErBaZhuangJiaInfo> call, Response<ErBaZhuangJiaInfo> response) {
                    ErBaZhuangJiaInfo body = response.body();
                    if (body == null) {
                        ToastUtils.showToast("请求错误");
                        return;
                    }
                    if (body.getStatus() != 1) {
                        ToastUtils.showToast(body.getInfo());
                        return;
                    }
                    zjInfo = body.getData();
                    initAdapter();
                }

                @Override
                public void onFailure(Call<ErBaZhuangJiaInfo> call, Throwable t) {
                    ToastUtils.showToast("网络请求错误");
                }
            });
        }
    }

    @Override
    public boolean isNeedLoadMore() {
        return false;
    }

    @Override
    protected void initAdapter() {
        if (type == 1) {
            if (mAdapter == null) {
                mAdapter = new ErBaRecordListAdapter(R.layout.item_erba_record_list,this);
                mAdapter.setNewData(xzInfo);
            } else {
                mAdapter.setNewData(xzInfo);
            }
        } else {
            if (mAdapter == null) {
                mAdapter = new ErBaTypeRecordListAdapter(R.layout.item_erba_record_list,this);
                mAdapter.setNewData(zjInfo);
            } else {
                mAdapter.setNewData(zjInfo);
            }
        }
        super.initAdapter();
    }
}
